<!DOCTYPE htm PUBLIC "-//W3C//DTD Xhtm 1.0 Transitional//EN" "DTD/xhtm1-transitional.dtd">
<htm xmlns="http://www.w3.org/1999/xhtm" xml:lang="de" lang="de">
<head>
 <meta http-equiv="content-type" content="text/htm; charset=iso-8859-1" />
 <meta http-equiv="content-style-type" content="text/css" />
 <meta name="author" content="Arlsair" />
 <meta name="date" content="2004-01-22" />
 <title>Blockbuster</title>
 <link rel="stylesheet" type="text/css" href="../../style.css" />
</head><body>
<h1>Blockbuster</h1>

<h2>&Uuml;bersicht</h2>
<b>Autor:</b> Ross Thomas<br />
<b>Version:</b> 0.7<br />
<b>Download:</b> <a href="http://www.avisynth.org/warpenterprises/" target="_blank">http://www.avisynth.org/warpenterprises/</a><br />
<b>Kategorie:</b> Verschiedenes<br />
<b>Anforderungen:</b> YV12 oder YUY2 Farbformat<br />
<hr>
<h2>Description</h2>
Blockbuster is an Avisynth filter designed to reduce or eliminate DCT blocks
			from an enocode. DCT blocks, also known as "dark blocks" when they appear in
			low-luma areas of a frame, are ugly, distracting artifacts that MPEG encoders
			like to scatter liberally over our otherwise flawless encodes.
		<p>While the severity of the problem varies between the different versions of MPEG,
			with MPEG-1 exhibiting the most DCT blocks and MPEG-4 the least, they do occur
			with all versions. MPEG-1 produces them almost anywhere there is a flat surface
			with a low detail level (such as a wall), and MPEG-2 shows them in the same
			areas but less frequently (they're particularly visible at lower bitrates, as
			anyone familiar with digital satellite can testify). MPEG-4 has signficantly
			less of a problem with low detail levels, but does still produce DCT blocks,
			especially in dark areas (see <a target="_blank" href="http://forum.doom9.org/showthread.php?s=&amp;threadid=31301">
				this Doom9 thread</a> for more on these blocks and MPEG-4).</p>
		<p>(Incidentally, DCT stands for "discrete cosine transform", and is one of the
			techniques MPEG uses to do its compression. They differ from macroblocks, which
			are most noticible in high-motion areas when the bitrate is insufficient to
			describe the motion accurately, and also from mosquito noise, which is an
			artifact that tends to appear around edges and areas of high contast.)</p>
		<p>As hinted at above, the cause of these blocks seems to be a lack of detail in
			areas of the picture, which the encoder fails to "see" and so applies too much
			compression. In the process what details were there are smoothed away and the
			area turns into a DCT block.</p>
		<p>The aim of this filter is to attempt to make those areas more "noticible" to the
			encoder so that it allocates more bits and thus doesn't need to compress so
			much. The astute amongst you will realise this filter is, basically, designed
			to increase the bitrate (and decrease the compressibility) of your clip. While
			this is considered a cardinal sin by most, there are at least two valid reasons
			for doing so.</p>
		<p>First, while the highest possible compression ratio is of course desirable, one
			has to consider the cost. No-one would accept a movie with a resolution of
			120x90, even though everyone knows it would have an excellent compression
			ratio. A similar effect could be achieved by smoothing the clip until it looks
			like you smeared your monitor screen with vasoline, but again no-one would
			accept this kind of image.</p>
		<p>It could be argued that DCT blocks are similarly unacceptable in a good-quality
			encode. Peoples' opinion on this differs greatly, but an increasing number,
			myself included, are looking for a sure-fire way to get rid of them. This
			filter is my contribution to the effort.</p>
		<p>Second, as compression technology evolves and improves it is sometimes necessary
			to re-encode old movies into new, more advanced formats. Removing artifacts
			from existing movies is much more difficult than stopping them appearing in the
			first place. Thus removing DCT blocks from your encodes now will make it easier
			to re-compress your movies later.</p>
		<h2>How it works</h2>
		<p>The filter splits each frame into a series of blocks (of user-configurable
			dimensions) and checks each block in turn for the amount of detail it contains.
			If the detail level is within the defined range then the block is processed
			according to the <i>method</i> parameter (see the <a href="#usage">Usage</a> section
			below).</p>
		<h2><a name="usage"></a>Usage</h2>
		<p>There are several methods that can potentially reduce or eliminate DCT blocks:
			adding noise, sharpening, and blurring. These different approaches are accessed
			with the <i>method</i> parameter, combined with a set of parameters shared by
			all methods as well as parameters specific to each one. There is an additional
			method called "show" which highlights each block that will be affected by the
			filter.</p>
		<p>The general form of usage is</p>
		<blockquote>
			<p>Blockbuster([clip], method="...", shared parameters, method-specific parameters)
			</p>
		</blockquote>
		<p>The <i>method</i> parameter can be either "noise", "dither", "sharpen", "blur"
			or "show". Parameters specific to each method will be listed in the <a href="#methods">
				Methods</a> section below. Parameters common to all methods are:</p>
		<table border="1">
			<tr>
				<th>
					Parameter</th>
				<th>
					Description</th>
				<th>
					Default</th>
			</tr>
			<tr>
				<td><i>block_size</i></td>
				<td>Determines the size of the blocks into which each frame is split before
					processing. The value represents both the width and height of the block, and
					cannot be less than 3.</td>
				<td>8</td>
			</tr>
			<tr>
				<td><i>detail_min</i>, <i>detail_max</i></td>
				<td>
					<p>Determines the amount of detail that must be present in a block for it to be
						processed. This value is a percentage, and can be between 1 and 100. It
						represents the percentage of unique brightness levels within the block.</p>
					<p>For example, if <i>block_size</i> is set to 8, each block contains 64 pixels. If <i>detail_min</i>
						is 1 and <i>detail_max</i> is 50, a block will only be processed if it contains
						between 1 and 32 unique brightness levels.</p>
					<p>A setting of <i>detail_min</i>=1, <i>detail_max</i>=100 will process the entire
						frame.</p>
				</td>
				<td>
					<p><i>detail_min</i>=1, <i>detail_max</i>=10</p>
				</td>
			</tr>
			<tr>
				<td><i>luma_offset</i>, <i>luma_threshold</i></td>
				<td>
					<p>Luma pixels in the range 0-<i>luma_threshold</i> will be offset by <i>luma_offset</i>
						within processed blocks.</p>
					<p>For example, if <i>luma_threshold</i> is 30 and <i>luma_offset</i> is -2, dark
						pixels (those with a luma between 0 and 30 inclusive) will have 2 subtracted
						from them, making them slightly darker still.</p>
					<p>(Rationale: It was discovered that Marc FD's mpeg2dec plugin's <i>lumoff</i> parameter
						seems to reduce the appearance of MPEG-4 "dark blocks" -- DCT blocks in dark
						areas of the frame -- further. These parameters are designed to do the same
						thing, but constrain the brightness change only to areas that seem to need it.)</p>
				</td>
				<td><i>luma_offset</i>=0, <i>luma_threshold</i>=25</td>
			</tr>
		</table>
		<h2><a name="methods"></a>Methods</h2>
		<h3>method="noise"</h3>
		<p>This method adds normally distributed -- also known as&nbsp;Gaussian
			--&nbsp;noise to the clip. Testing has shown that Gaussian noise is far more
			suitable for this filter's purposes than uniformly distributed noise.</p>
		<p>With uniformly distributed noise, each possible value is as likely to occur as
			any other. That is, if you generate a sequence of numbers in the range 1-100,
			at any point in the sequence you are as likely to generate a 5 as a 95.</p>
		<p>"Normally distributed" means the chance of each value occurring is not equal.
			Let's say you generate normally distributed numbers with a mean of 0 and a
			variance of 1 (for an explanation of these terms see the links at the end of
			the paragraph). The generator can in theory spit out <i>any</i> number that can
			fit into a double-precision floating point, but taken as a whole the numbers
			will average out to zero (that's what mean=0, er, means). With these parameters
			about 68% of the values will be between -1 and 1, about 95% between -2 and 2,
			and about 99% between -3 and 3. The probability of generating numbers that are
			significantly higher or lower is very small indeed, with the probability
			getting smaller the further away from zero you get. You'd need to make billions
			of Gaussian random numbers with mean 0, variance 1 before you saw, for example,
			the value 9 being generated. You can read more about normal distribution <a href="http://www.robertniles.com/stats/stdev.shtml">
				here</a> and <a href="http://davidmlane.com/hyperstat/A16252.html">here</a>.</p>
		<p>Gaussian noise very much tends to concentrate around the specified mean, and is
			thus more "natural" than uniformly distributed noise. Most things in nature
			(including spring precipitation, calorific intake, and, of course, noise)
			cluster around a "normal" value, with progressively less frequent occurrances
			as you get further from that norm.</p>
		<p>
			You can read more about adding noise to eliminate DCT blocks in <a href="http://arstechnica.infopop.net/OpenTopic/page?a=tpc&amp;s=50009562&amp;f=67909965&amp;m=3890938134&amp;r=5470927074">
				this Ars Technica thread</a> (edit Wilbert: I can't find the
            relevant thread anymore).</p>
		<blockquote>
			<p>Blockbuster([clip], method="noise", common parameters, float <EM>mean</EM>,
				float <EM>variance</EM>, int <EM>cache</EM>, int <EM>seed</EM>)</p>
		</blockquote>
		<table border="1">
			<tr>
				<th>
					Parameter</th>
				<th>
					Description</th>
				<th>
					Default</th>
			</tr>
			<tr>
				<td><EM>mean</EM>, <EM>variance</EM></td>
				<td>The mean and variance of the generated random noise.</td>
				<td><EM>mean</EM>=0, <EM>variance</EM>=1</td>
			</tr>
			<tr>
				<td><i>cache</i></td>
				<td>
					<p>Because the generation of Gaussian numbers is very slow, to achieve reasonable
						performance Blockbuster creates a cache of random numbers at startup. This
						parameter spcifies the size of the cache in kilobytes. While you can set this
						value to any positive number, it's best to keep it fairly large in order to
						maintain properly random noise.</p>
					<p>While the default may seem quite big, consider this: If you have a block size of
						8, then each block has an area of 64 pixels. Each pixel requires 2 bytes to
						describe it, so a processed block will consume 128 bytes of random data. If 10%
						of the blocks in a 640x480 frame are processed, this will require nearly 62kb
						of random numbers.</p>
				</td>
				<td>256</td>
			</tr>
			<TR>
				<TD><EM>seed</EM></TD>
				<TD>
					<P>By default the pseudo-random number generator will use the system's current time
						as its seed value.&nbsp;For certain applications where predictable results are
						desired, the <EM>seed</EM> parameter can be used to override this default, thus
						providing the same "random" noise each time the filter is run.</P>
					<P>The seed can be any number from 0 to 2,147,483,647. When zero, the system's
						current time is used.</P>
				</TD>
				<TD>0</TD>
			</TR>
		</table>
		<h3>method="dither"</h3>
		<P>This method is very similar to the "noise" method, with the only difference
			being this method will add the same noise to each frame of the clip, whereas
			the "noise" method will add different noise to each frame. The effect of this
			is hard to describe, but easy to see, so try it for yourself with a high
			variance. The closest comparison I can think of is that this method produces an
			effect similar to watching the movie through speckled glass.</P>
		<P>The reason I added this method is because I found when using method="noise" that
			the constantly changing nature of the noise produced motion in otherwise static
			areas of the frame, particularly when using a low bit rate. It is my hope that
			using the same noise for each frame will prevent artificial motion in static
			areas. This should be considered experimental.</P>
		<BLOCKQUOTE dir="ltr" style="MARGIN-RIGHT: 0px">
			<P>Blockbuster([clip], method="dither", common parameters, float <EM>mean</EM>,
				float <EM>variance</EM>, int <EM>seed</EM>)</P>
		</BLOCKQUOTE>
		<P dir="ltr">For a description of this method's parameters, see the "noise" method
			above. Note however that the "dither" method has no <EM>cache</EM> parameter
			since it always generates only enough noise for one frame.</P>
		<H3>method="sharpen"</H3>
		<p>This method applies a basic (and fast) sharpening filter to processed blocks. In
			this way it "amplifies" detail already present in the block rather than adding
			new noise.</p>
		<blockquote>
			<p>Blockbuster([clip], method="sharpen", common parameters, int <i>strength</i>)</p>
		</blockquote>
		<table border="1">
			<tr>
				<th>
					Parameter</th>
				<th>
					Description</th>
				<th>
					Default</th>
			</tr>
			<tr>
				<td><i>strength</i></td>
				<td>Specifies the strength of the sharpening, from 1-100.</td>
				<td>25</td>
			</tr>
		</table>
		<h3>method="blur"</h3>
		<p>This method applies a 3x3 blur to processed blocks. It is currently
			experimental, since in theory reducing the frequency of already low-frequency
			blocks will not reduce the appearance of DCT blocks. It's worth a try, though
			:).</p>
		<blockquote>
			<p>Blockbuster([clip], method="blur", common parameters, int <i>strength</i>)</p>
		</blockquote>
		<table border="1">
			<tr>
				<th>
					Parameter</th>
				<th>
					Description</th>
				<th>
					Default</th>
			</tr>
			<tr>
				<td><i>strength</i></td>
				<td>Specifies the strength of the blurring, from 1-100.</td>
				<td>25</td>
			</tr>
		</table>
		<h3>method="show"</h3>
		<p>This method highlights blocks that will be processed using the specified
			block-related common parameters (<i>block_size</i>, <i>detail_min</i>, and <i>detail_max</i>).
			It is mainly useful as a visual aid in setting the detail thresholds to the
			desired range.</p>
		This method has no additional parameters.
		<h2>TODO</h2>
		<ul>
			<li>
			MMX/SSE optimizations (I have to learn x86 assembler first...).
			<li>
				Unsharp mask method.</li>
		</ul>
<h2>Author</h2>
<p>Ross Thomas &lt;ross(at)grinfinity.com&gt;</p>
	</body>
</html>
